#include "landblockmask.h"

LandBlockMask::LandBlockMask(QWidget *parent)
    :QPushButton(parent)
{
    this->setAutoFillBackground(true);
    this->setPalette(QPalette(Qt::gray));
    this->resize(parent->size());
    this->setFlat(true);
//    connect(this, &QPushButton::clicked, this, &LandBlockMask::markBlock);
    initialize();
}

void LandBlockMask::initialize()
{
    isMark = false;
}

void LandBlockMask::markBlock()
{
    if (!isMark) {
        this->setPalette(QPalette(Qt::blue));
    }
    else {
        this->setPalette(QPalette(Qt::gray));
    }
    isMark = !isMark;
}

void LandBlockMask::mousePressEvent(QMouseEvent *event)
{
    // 左击发出按钮按下的信号QPushButton::clicked()
    // （维持原有功能）
    if (event->button() == Qt::LeftButton) {
        emit QPushButton::clicked();
    }

    // 右击执行需要执行的函数，也可以发出信号
    if (event->button() == Qt::RightButton) {
        markBlock();
    }
}
